
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@page import="com.tss.util.*"%>
<%@page import="com.jedi.*"%>
<%@page import="com.store.*"%>
<%@page import="com.store.Task"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>

<%@page import ="java.sql.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>
<%
User just_user = (User)session.getAttribute("LoginUser");
String power_enable_id = "10110";
String power1_enable_id = "10010";
if (!(just_user.hasPower(power_enable_id)&& just_user.hasPower(power1_enable_id))) {
	out.println(strNoPowerInfo); 
	return;
}
String contype_session = ParamUtils.getParameter(request,"contype_session","1");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String taskid       = ParamUtils.getParameter(request,"taskid","");
String area_id        = ParamUtils.getParameter(request,"area_id","");
String cusname           = ParamUtils.getParameter(request,"cusname","");
String linkman     = ParamUtils.getParameter(request,"linkman","");
String phone          = ParamUtils.getParameter(request,"phone","");
String addr             = ParamUtils.getParameter(request,"addr","");
String prjname          = ParamUtils.getParameter(request,"prjname","");
String conid        = ParamUtils.getParameter(request,"conid","");
String   begin_date        = ParamUtils.getParameter(request,"begin_date",TSSDate.shortDate());
String end_date          = ParamUtils.getParameter(request,"end_date",TSSDate.shortDate());
String taskscore       = ParamUtils.getParameter(request,"taskscore","0");
String scoreman       = ParamUtils.getParameter(request,"scoreman","");
String scoretime    = ParamUtils.getParameter(request,"scoretime","0");
String saleid    = ParamUtils.getParameter(request,"saleid","0");
String matterinfo             = ParamUtils.getParameter(request,"matterinfo","");
String servicelog        = ParamUtils.getParameter(request,"servicelog","");
//String diffmod            = ParamUtils.getParameter(request,"diffmod","1");
String   taskaddress        = ParamUtils.getParameter(request,"taskaddress","");
String triptype          = ParamUtils.getParameter(request,"triptype","0");
String normaltime     = ParamUtils.getParameter(request,"normaltime","0");
String worktime     = ParamUtils.getParameter(request,"worktime","0");
String tasktime       = ParamUtils.getParameter(request,"tasktime","0");
String pay    = ParamUtils.getParameter(request,"pay","false");
String tripfee        = ParamUtils.getParameter(request,"tripfee","0.00");
String outefee            = ParamUtils.getParameter(request,"outefee","0.00");
String spartfee            = ParamUtils.getParameter(request,"spartfee","0.00");
String   tasklile       = ParamUtils.getParameter(request,"tasklile","");
String cmd = ParamUtils.getParameter(request,"cmd","");

String strErr = "";
if (cmd.trim().equals("insert")) {

	
	if (strErr.trim().equals("") && conid.trim().equals("")) {
		strErr = "请选择合同!";
	}
	
	if (strErr.trim().equals("") && area_id.trim().equals("")) {
		strErr = "请选择区域!";
	}
	if (strErr.trim().equals("") && cusname.trim().equals("")) {
		strErr = "请输入客户名称!";
	}
	
	if (strErr.trim().equals("") && matterinfo.length() >= 600) {
		strErr = "服务内容在600字以内!";
	}
	if (strErr.trim().equals("") && servicelog.length() >= 600) {
		strErr = "工作纪要在600字以内!";
	}
	if (strErr.trim().equals("")) {
		try {
			Integer.parseInt(normaltime);
		}
		catch(Exception ex) {
			strErr = " 正常工作量应为整数!";
		}
	}
	
	if (strErr.trim().equals("")) {
		try {
			Integer.parseInt(worktime);
		}
		catch(Exception ex) {
			strErr = " 加班工作量应为整数!";
		}
	}
	if (strErr.trim().equals("")) {
		try {
			Integer.parseInt(tasktime);
		}
		catch(Exception ex) {
			strErr = "实际工作量应为整数!";
		}
	}
		if (strErr.trim().equals("")) {
		try {
			Float.parseFloat(tripfee);
		}
		catch(Exception ex) {
			strErr = "差旅费输入错误!";
		}
	}	
	if (strErr.trim().equals("")) {
		try {
			Float.parseFloat(spartfee);
		}
		catch(Exception ex) {
			strErr = " 备件成本输入错误!";
		}
	}
	if (strErr.trim().equals("")) {
		try {
			Float.parseFloat(outefee);
		}
		catch(Exception ex) {
			strErr = " 外部人员技术成本输入错误!";
		}
	}

	
	if (strErr.trim().equals("")) {
	FormatDate formatDate = new FormatDate();
		Task task = new Task();
	
		task.setArea_id(area_id);
		task.setCusname(cusname);
		task.setLinkman(linkman);
		task.setPhone(phone);
		task.setAddr(addr);
		task.setStatus(0);
		task.setBegindate(formatDate.toDate(begin_date));
		task.setEnddate(formatDate.toDate(end_date));
		task.setTaskscore(Integer.parseInt(taskscore));
		task.setScoreman(scoreman);
		task.setScoretime(formatDate.toDate( scoretime));
		task.setMatterinfo(matterinfo);
		task.setServicelog(servicelog);
		task.setDiffmod(0);
		task.setTaskaddress(taskaddress);
		task.setTriptype(Integer.parseInt(triptype));
		task.setWorktime(Integer.parseInt( worktime));
		task.setTasktime(Integer.parseInt( tasktime));
		task.setTripfee(Double.parseDouble(tripfee));
		task.setConid(Integer.parseInt(conid));
		
		task.setSpartfee(Double.parseDouble(spartfee));
			task.setOutefee(Double.parseDouble(outefee));
		task.setNormaltime(Integer.parseInt( normaltime));
		task.setEngineerid(just_user.getId());
		task.setPrjname(prjname);
		task.setTasklile(tasklile);
		task.insert();
		if (task.hasErr()) strErr = task.getErrHtml();
	}
}

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'task_add.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    
   <link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript">
function clk_submit() {
	var oForm = document.operatorForm;
	oForm.cmd.value = "insert";
	return true;
}

function clk_insert_rate(contract_id,intType) {
	var str = "contract_rate_insert.jsp?rate_type=" + intType + "&contract_id=" + contract_id;
	var r = window.showModalDialog('selectFrm.htm',str,'dialogHeight: 300px;dialogWidth: 400px;center:yes;dialogHide:no;status:no;help: no');
   	if(r != null)
   	{
   		ifrmActiveArea.location.href = "contract_rate_refresh.jsp?rate_type=" + intType + "&contract_id=" + contract_id;
   	}
}
function clk_sel_businfo(){
var str = "salecontract_mgt/contract_sel_bus.jsp";
	var oForm = document.operatorForm;
	var r = window.showModalDialog('../selectFrm.htm',str,'dialogHeight:500px;dialogWidth: 500px;center:yes;dialogHide:no;status:no;help: no');
   	if(r != null)
   	{
   		var valArray = r.split(",");
   			oForm.busid.value = valArray[0];
   			oForm.busname.value = valArray[4];
   		
   	}
}



function upload_file() {
	var oForm = document.operatorForm;
	var r = window.showModalDialog('../selectFrm.htm','task_mgt/tasklile_upload.jsp','dialogHeight: 200px;dialogWidth: 300px; center: yes; status:no;help: no');
	if(r && r != "") {
		oForm.tasklile.value = r;
	}
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td >
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			
			<tr>
				<td height="100" align="center" valign="top"
					style="padding-top:20px;padding-bottom:10px;">
					<form name="operatorForm" method="get" onsubmit="return clk_submit();">
				<table width="88%" border="0" cellpadding="3" cellspacing="1"
					bgcolor="#FFFFFF">
				 <tr>
                <td height="24" colspan="7" bgcolor="#EDEDF0" style="padding-left:10px;">
                提示：<font color="red">*</font> 号为必填项，请您认真填写                </td>
              </tr>
               <%if (!strErr.trim().equals("")) {%>
              <tr> 
                <td height="24" colspan="3" bgcolor="#D7D7DB" style="padding-left:10px;">
                  错误提示：
                 
                  <font color=red><%=strErr%></font>   
                   </td>
              </tr>
              <%}%>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB">所在区域：</td>
						<td bgcolor="#EDEDF0"> 
					 <select name="area_id"  style="width:70px">
                    <%for(int i=0;i<area_item_info.length;i++){%>
                    <option value="<%=area_item_info[i]%>"<%if (area_id.trim().equals(area_item_info[i])){%> selected<%}%>><%=area_item_info[i]%></option>
                    <%}%>
                  </select>   
                     </td>
				    </tr>
				    	<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">所属合同号：</td>
						<td bgcolor="#EDEDF0">
						<input name="conid" type="text"value="<%=conid%>" size="30" maxlength="25" class="inputbox" readonly="readonly" style="background-color:#EDEDE8">
				
						</td>
					</tr>
					<tr>
						<td height="22" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
						客户名称<span  style="padding-;left:5px;"><font color="red">*</font></span></td>
						<td bgcolor="#EDEDF0">
						<input name="cusname" type="text"  value="<%=cusname%>" size="50" maxlength="50" class="inputbox"></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">客户联系人：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;"><input name="linkman" type="text"
					 size="30" maxlength="25" value="<%=linkman%>" class="inputbox">
							
							</td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
							联系电话：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;"><input name="phone" type="text"
							value="<%=phone%>" size="30" maxlength="50" class="inputbox"></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
							联系地址：</td>
						<td bgcolor="#EDEDF0"  style="padding-left:5px;"><input name="addr" type="text"
							value="<%=addr%>" size="80" maxlength="80" class="inputbox"></td>
					</tr>
						
					
				
				
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
						服务预计开始日期：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;">
						 <span id="htmlBeginTime">&nbsp;</span> 
						 </td>
					</tr>
					
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
						服务预计结束日期：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;">
						<span id="htmlEndTime" >&nbsp;</span>
						</td>
					</tr>
					
					<%--<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">正常工作量(小时)：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;"><input name="normaltime" type="text"
							value="<%=normaltime%>" size="30" maxlength="25" class="inputbox"></td>
					</tr>
					--%><tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">加班工作量(小时)：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;"><input name="worktime" type="text"
							value="<%=worktime%>" size="30" maxlength="25" class="inputbox"></td>
					</tr>
					
					<%--<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">	实际工作量(天)：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;">
						 <input name="tasktime" type="text" value="<%=tasktime%>" size="30" maxlength="25" class="inputbox">
						 </td>
					</tr>
						--%><tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
						出差地点：</td>
					  <td bgcolor="#EDEDF0" style="padding-left:5px;">
					  <input name="taskaddress" type="text" value="<%=taskaddress%>" size="80" maxlength="80" class="inputbox">
					  </td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
						出差方式：</td>
					   	 <td bgcolor="#EDEDF0" style="padding-left:5px;" >
							    <select name="triptype" style="width:70px" >
									<option value="1"  <%if (Integer.parseInt(triptype)==1 ){%>selected <%}%>>飞机</option>
									
									<option value="2" <%if (Integer.parseInt(triptype)==2 ){%>selected <%}%>>火车</option>
									
									<option value="3" <%if (Integer.parseInt(triptype)==3 ){%>selected <%}%>>汽车</option>
									<option value="4" <%if (Integer.parseInt(triptype)==4){%>selected <%}%>>其它</option>
								</select>
						</td>
					</tr>
					<%if(just_user.hasPower("10210")){%>
				<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">差旅费：</td>
					  <td bgcolor="#EDEDF0" style="padding-left:5px;"><input name="tripfee" type="text"
							value="<%=tripfee%>" size="30" maxlength="25" class="inputbox">
					    ￥</td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB">备件成本：</td>
					  <td bgcolor="#EDEDF0" style="padding-left:5px;"><input name="spartfee" type="text"
							value="<%=spartfee%>" size="30" maxlength="25" class="inputbox">
					    ￥</td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">外部人员技术成本：</td>
				      <td bgcolor="#EDEDF0" style="padding-left:5px;"><input name="outefee" type="text"
							value="<%=outefee%>" size="30" maxlength="25" class="inputbox">
				        ￥</td>
					</tr>
					<%}%>
					
					<tr> 
    				<td height="24" bgcolor="#D7D7DB" style="padding-right:5px;" align="right" >工单附件：</td>
    				<td bgcolor="#EDEDF0" style="padding-left:5px;">
     				 <input type="text" name="tasklile" value="<%=tasklile%>" size="30" maxlength="50" readonly="readonly" style="background-color:#EDEDE8"> 
     					 <input type="button" value="上传附件" class="inputButton" onclick="upload_file();"> 
   							 </td>
 					 </tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
							服务内容：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;"><textarea name="matterinfo" cols="50" rows="4" class="inputarea"><%=matterinfo%></textarea></td>
					</tr>
					<tr>
						<td height="24" align="right" bgcolor="#D7D7DB" style="padding-right:5px;">
							工作记要：</td>
						<td bgcolor="#EDEDF0" style="padding-left:5px;"><textarea name="servicelog" cols="50" rows="4" class="inputarea"><%=matterinfo%></textarea></td>
					</tr>
					<tr bgcolor="#EDEDF0">
						
						<td  align="center" colspan="2">
								<input type="submit" name="submit" value="添加" class="inputButton">
							 <input type="reset" name="reset" value="重 写" class="inputButton">
							 <input type="hidden" name="cmd" value="">
							  <input type="hidden"  name="contype_session" value="<%=contype_session%>" > 
							 </td>
					</tr>
				</table>
				</form>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
<%if (cmd.equals("insert") && strErr.trim().equals("")){%>
<script language="javascript">
alert("工单添加成功系统将返回首页!");
var oForm=document.operatorForm;
parent.location.href="../task_mgt/task_main.jsp";


</script>
<%}%>

<script language="javascript">
	htmlBeginTime.innerHTML = showCalenderInput("begin_date","operatorForm","<%=begin_date%>",1);
	htmlEndTime.innerHTML = showCalenderInput("end_date","operatorForm","<%=end_date%>",1);
</script>
</body>
</html>
